﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Simple.Services;
using Simple.Services.System.QHSEViolationCategory.Models;

namespace Simple.WebApi.Controllers.System;

/// <summary>
/// 体系要素管理
/// </summary>
[Route("QHSEViolationHSE/[action]")]
[ApiController]
public class QHSEViolationHSEController : ControllerBase
{
    private readonly QHSEViolationHSEService _violationHSEService;

    public QHSEViolationHSEController(QHSEViolationHSEService violationHSEService)
    {
        _violationHSEService = violationHSEService;
    }
    /// <summary>
    /// 体系要素列表
    /// </summary>
    [HttpGet]
    [CustomAuthorize("hdv_qhse_data")]
    public async Task<AppResult> List()
    {
        List<QHSEViolationHSEModel> menus = await _violationHSEService.GetAsync();
        return AppResult.Status200OK(data: menus);
    }
    [HttpGet]
    [ValidateTimestampAndSignature]
    public async Task<AppResult> List1()
    {
        List<QHSEViolationHSEModel> menus = await _violationHSEService.GetAsync();
        return AppResult.Status200OK(data: menus);
    }
    [HttpGet]
    [CustomAuthorize("hdv_qhse_data")]
    public async Task<AppResult> Page([FromQuery] QHSEViolationHSEPageInputModel model)
    {
        PageResultModel<QHSEViolationHSEModel> data = await _violationHSEService.GetPageAsync(model);
        return AppResult.Status200OK(data: data);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_data")]
    public async Task<AppResult> Add([FromBody] QHSEViolationHSEModel model)
    {
        await _violationHSEService.AddAsync(model);
        return AppResult.Status200OK("新增成功");
    }

    [HttpPost]
    [CustomAuthorize("hdv_qhse_data")]
    public async Task<AppResult> Edit([FromBody] QHSEViolationHSEModel model)
    {
        await _violationHSEService.UpdateAsync(model);
        return AppResult.Status200OK("更新成功");
    }

    [HttpDelete]
    [CustomAuthorize("hdv_qhse_data")]
    public async Task<AppResult> Delete([FromBody] List<IdInputModel> model)
    {
        await _violationHSEService.DeleteAsync(model.Select(m => m.Id));
        return AppResult.Status200OK("删除成功");
    }
}
